﻿CREATE FUNCTION [dbo].[GL_Credit]
(	@ApplID int
)RETURNS TABLE AS
RETURN ( 

SELECT     v_CreditInfo.LoanID, v_CreditInfo.DatePulled, v_CreditInfo.Installment, v_CreditInfo.Revolving, v_CreditInfo.MortgageStatus, v_CreditInfo.PriorRepos, 
                      v_CreditInfo.ReposCount, v_CreditInfo.ExcelAutoCredit, v_CreditInfo.PosAutoCredit, v_CreditInfo.PosAutoAfterRepo, v_CreditInfo.AutoCreditCount, 
                      v_CreditInfo.AutoCreditCount_ALL, v_CreditInfo.OpenUnitsAdjusted, v_CreditInfo.PriorPayCar, v_CreditInfo.HighCredit, v_CreditInfo.PayHistory, 
                      v_CreditInfo.DerogCountAfterBK, v_CreditInfo.CurrDerogCredit, v_CreditInfo.PosCreditTime, v_CreditInfo.MaxPaymentHist, v_CreditInfo.CurrDerogAuto, 
                      v_CreditInfo.GoodToAllAcctRatio, v_CreditInfo.PosAutoAfterBK, v_CreditInfo.LastLate, v_CreditInfo.LastLate_Auto, v_CreditInfo.PastDueRatio, 
                      v_CreditInfo.BalanceToHighCredit, v_CreditInfo.AverageStatus, v_CreditInfo.Ghost, v_CreditInfo.LastLastDate, v_CreditInfo.PosCreditCount, 
                      v_CreditInfo.CurrCreditCount, v_CreditInfo.ReportXML, v_CreditInfo.ReportMerged, v_CreditInfo.ScoreEfx, v_CreditInfo.ScoreXpn, v_CreditInfo.ScoreTU, 
                      v_CreditInfo.ScoreTri, v_CreditInfo.Chapter7_FileDate, v_CreditInfo.Chapter7_SatisfiedDate, v_CreditInfo.Chapter7_Status, 
                      v_CreditInfo.Chapter7_Count, v_CreditInfo.Chapter13_FileDate, v_CreditInfo.Chapter13_SatisfiedDate, v_CreditInfo.Chapter13_Status, 
                      v_CreditInfo.Chapter13_Count, v_CreditInfo.ForeclosureNOD_FileDate, v_CreditInfo.ForeclosureNOD_SatisfiedDate, 
                      v_CreditInfo.ForeclosureNOD_Status, v_CreditInfo.ForeclosureNOD_Count, v_CreditInfo.BK_FC_NOD_Count, v_CreditInfo.DebtRatio, 
                      v_CreditInfo.CashReserveMos, v_CreditInfo.MortgageCount, v_CreditInfo.MortgageMonthReviewedMax, v_CreditInfo.MortgageSince, 
                      v_CreditInfo.MortgageHistory_30, v_CreditInfo.MortgageHistory_60, v_CreditInfo.MortgageHistory_90, v_CreditInfo.MortgageHistory_120, 
                      v_CreditInfo.TradeLinesTotal, v_CreditInfo.TradeLinesCount_30, v_CreditInfo.TradeLinesCount_60, v_CreditInfo.TradeLinesCount_90, 
                      v_CreditInfo.TradeLinesCount_120, v_CreditInfo.ChargeOffsCount, v_CreditInfo.ChargeOffsAmount, v_CreditInfo.TradeLinesCount_ActiveOpen_03, 
                      v_CreditInfo.TradeLinesCount_ActiveOpen_06, v_CreditInfo.TradeLinesCount_ActiveOpen_12, v_CreditInfo.TradeLinesCount_ActiveOpen_24, 
                      v_CreditInfo.TradeLinesCount_ActiveOpen_12_1000, v_CreditInfo.TradeLinesCount_ActiveOpen_12_5000, v_CreditInfo.TradeLinesCount_MR_24_5000, 
                      v_CreditInfo.PaymentDelayAverage, v_CreditInfo.MortgageLate, v_CreditInfo.RepoCount, v_CreditInfo.OpenBK, v_CreditInfo.PhoneUtilityCollection, 
                      v_CreditInfo.SSN_DL, v_CreditInfo.AddressMatches, v_CreditInfo.AnyWho, v_CreditInfo.DLSuspended, v_CreditInfo.HousePayment, 
                      v_CreditInfo.GrossIncome, v_CreditInfo.RepoAfterBK, v_CreditInfo.DebtNoCar, PC.DealerID, PC.BookValue, PC.BookValueDesc, PC.ModelAge, 
                      PC.Mileage, PC.MilesPerYear, PC.DownPayment, PC.LoanTerm, PC.NumberOfPayments, PC.AmountFinanced, PC.APR, PC.Payment, 
                      PC.DownPaymentRatio, PC.DTI, PC.PTI, PC.PLTV, PC.JobTimeCurrent,
PC.MonthsCurrent ResidenceTimeCurrent, PC.MonthsInArea ResidenceTimeInAreaCurrent,PC.CurrPrevDistance ResidenceDistance,
LoanTermInMonth
FROM         v_CreditInfo INNER JOIN
                      v_PurchaseContract AS PC ON v_CreditInfo.LoanID = PC.LoanID
WHERE (v_CreditInfo.LoanID = @ApplID)
)








